package com.huawei123.hasee.mynavigationview_view.TableLayoutAndViewPage;

import android.annotation.TargetApi;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.huawei123.hasee.mynavigationview_view.R;


/**
 * 项目名称：MyNavigationView_view
 * 类描述：通用的Fragment
 * 创建人：hasee
 * 创建时间：2017/6/23 20:55
 * 修改人：hasee
 * 修改时间：2017/6/23 20:55
 * 修改备注：
 */
public class NewsDetailFragment extends Fragment {

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle
            savedInstanceState) {
        final TextView textView = new TextView(getContext());
        Bundle bundle = getArguments();//得到Tablayout传过来的数据
        final String item = bundle.getString("title");//传过来的初始化条目展示的标题
        final int position = bundle.getInt("position");//标题位置
        textView.setBackgroundColor(Color.rgb((int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math
                .random() * 255)));//检测用的切换背景颜色
        textView.setText(item);
        //示例化自定义Tab布局
        final TabLayoutAndViewPagerActivity.ActivityParameter tab = (TabLayoutAndViewPagerActivity.ActivityParameter)
                bundle.getSerializable("tab");
        final TabLayout.Tab tabAt = tab.getTabAt();
        final View inflate = LayoutInflater.from(getContext()).inflate(R.layout.tablayout_item, null);
        TextView mTV_title = (TextView) inflate.findViewById(R.id.mTV_title);
        mTV_title.setText(item);
        final TextView mTV_pop = (TextView) inflate.findViewById(R.id.mTV_pop);
        mTV_pop.setBackground(getResources().getDrawable(R.drawable.pop_image));
        //这块写的是点击fragment改变tab条目作为测试方法
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String number =String.valueOf((int) (Math.random() * 99));
                textView.setText( item + "------" + number);
                mTV_pop.setText(number);
                tabAt.setCustomView(null);//改变前清空一下
                tabAt.setCustomView(inflate);


            }
        });
        return textView;
    }
}
